<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>基本信息</title>
    <link rel="stylesheet" href="/common/layuimini/layui.css" media="all">
</head>
<body>
<div class="layui-form-pane" style=" width: 750px; text-align: center;margin: 0 auto;">

  <form class="layui-form">
    <h2 style="margin: 20px; font-weight: bold">修改基本信息</h2>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label">用户昵称<span style="color:red;">*</span></label>
        <div class="layui-input-inline">
          <input type="text" name="nickname" lay-verify="required" lay-reqtext="用户名是必填项" autocomplete="off" placeholder="请输入标题" class="layui-input">
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">邮箱<span style="color:red;">*</span></label>
        <div class="layui-input-inline">
          <input type="text" name="email" lay-verify="email" autocomplete="off" placeholder="请输入标题" class="layui-input">
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label">个人描述</label>
        <div class="layui-input-inline">
          <input type="text" name="description" autocomplete="off" placeholder="请输入标题" class="layui-input">
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">电话</label>
        <div class="layui-input-inline">
          <input type="text" name="phone" autocomplete="off" placeholder="请输入标题" class="layui-input">
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label">地址</label>
        <div class="layui-input-inline">
          <input type="text" name="address" autocomplete="off" placeholder="请输入标题" class="layui-input">
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-inline">
          <input type="radio" name="sex" value="1" title="男">
          <input type="radio" name="sex" value="0" title="女">
        </div>
      </div>
    </div>

    <div class="layui-btn-container" style="margin: 35px 10px;position: fixed;bottom: 0;right: 5%;">
      <button type="button" style="width: 100px;" class="layui-btn layui-btn-normal layui-btn-radius layui-btn-sm" lay-submit lay-filter="materialBtn">保存</button>
      <button type="button" style="width: 100px;" class="layui-btn layui-btn-primary layui-btn-radius layui-btn-sm" onclick="closeIframe()">取消</button>
    </div>
  </form>
</div>
</body>
<script type="text/javascript" src="/common/layui/layui.js"></script>
<script type="text/javascript" src="/common/jquery-1.11.3.js"></script>
<script type="text/javascript" src="/common/xm-select/xm-select.js"></script>
<script type="text/javascript" src="/common/layer/layer.js"></script>
<script>

  window.onload = function () {
  }




  layui.use(['form'],function (){

    var form = layui.form;

    //赋值表单
    setUserMaterial();

    function setUserMaterial(){
      //用户昵称
      var materialNickname = $("#materialNickname",parent.document).html();
      //用户邮箱
      var materialEmail = $("#materialEmail",parent.document).html();
      //个人描述
      var materialDescription = $("#materialDescription",parent.document).html();
      //电话
      var materialPhone = $("#materialPhone",parent.document).html();
      //地址
      var materialAddress = $("#materialAddress",parent.document).html();
      //性别
      var materialSex = $("#materialSex",parent.document).html();

      //取值完毕，开始操作
      $('input[name = nickname]').val(materialNickname);
      $('input[name = email]').val(materialEmail);
      $('input[name = description]').val(materialDescription);
      $('input[name = phone]').val(materialPhone);
      $('input[name = address]').val(materialAddress);
      if (materialSex == '男'){
        $("input[name='sex'][value='1']").attr("checked",true);
      }
      if (materialSex == '女'){
        $("input[name='sex'][value='0']").attr("checked",true);
      }
      form.render();
    }

    form.on('submit(materialBtn)',function (obj){

      var userId = $("#userId",parent.document).val();
      $.ajax({
        url: "/user/index/saveMaterial",
        data:{
          "userId":userId,
          "nickname": obj.field.nickname,
          "email": obj.field.email,
          "description": obj.field.description,
          "phone": obj.field.phone,
          "address": obj.field.address,
          "sex": obj.field.sex,
        },
        type: "post",
        dataType: "json",
        success:function (res){
          if (res.state == false){
            layer.msg(res.msg,{icon:2,time:800})
          }else {
            layer.msg("保存成功",{icon:1,time:800})
            var index = parent.layer.getFrameIndex(window.name);//获取当前iframe层的索引
            parent.layer.close(index);//执行关闭
            parent.location.reload();
          }
        }
      })
    })
  })

  function closeIframe(){
    var index = parent.layer.getFrameIndex(window.name);//获取当前iframe层的索引
    parent.layer.close(index);//执行关闭
  }
</script>
</html>
